package com.ase.leetcode.数组中重复的数字;

/**
 * @author gyhstart
 * @create 2021/4/26 - 0:43
 **/
public class Solution3 {
    public static int findRepeatNumber(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            while (i != nums[i]) {
                if (nums[i] == nums[nums[i]]) {
                    return nums[i];
                }
                int temp = nums[nums[i]];
                nums[nums[i]] = nums[i];
                nums[i] = temp;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int repeatNumber = findRepeatNumber(new int[]{2, 3, 1, 0, 2, 5});
        System.out.println("repeatNumber = " + repeatNumber);
    }
}
